package com.EAIPClub.ResourcesInfoManager.mapper;

import com.api.POJO.ResourcesInfoManager.ResourcesInfoManagerBaseInfo;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Description :静态资源信息管理模块资源基本信息Mapper
 * @Author :崔昌赫
 * @Date : 2021/11/2
 */
@Repository
@Mapper
public interface ResourcesInfoManagerBaseInfoMapper {
    @Insert("INSERT INTO res_baseinfo VALUES (null,'baseInfo.uid','baseInfo.filename','baseInfo.filesize','baseInfo.date','baseInfo.md5','baseInfo.hdfs','baseInfo.location')")
    Boolean addNewBaseInfo(@Param("baseInfo") ResourcesInfoManagerBaseInfo baseInfo);

    @Select("SELECT * FROM res_baseinfo WHERE 1=1")
    List<ResourcesInfoManagerBaseInfo> findAllBaseInfo();

    @Select("SELECT * FROM res_baseinfo WHERE id='${id}'")
    ResourcesInfoManagerBaseInfo findBaseInfoById(@Param("id")Integer id);
    @Select("SELECT * FROM res_baseinfo WHERE uid='${uid}'")
    ResourcesInfoManagerBaseInfo findBaseInfoByUid(@Param("uid")String uid);
    @Select("SELECT * FROM res_baseinfo WHERE filename='${filename}'")
    List<ResourcesInfoManagerBaseInfo> findBaseInfoByFileName(@Param("filename")String filename);
    @Select("SELECT * FROM res_baseinfo WHERE filesize=${filesize}")
    List<ResourcesInfoManagerBaseInfo> findBaseInfoByFileSize(@Param("filesize")Double filesize);
    @Select("SELECT * FROM res_baseinfo WHERE date = '${date}'")
    List<ResourcesInfoManagerBaseInfo> findBaseInfoByDate(@Param("date")String date);
    @Select("SELECT * FROM res_baseinfo WHERE md5='${md5}'")
    ResourcesInfoManagerBaseInfo findBaseInfoByMD5(@Param("md5")String md5);
    @Select("SELECT * FROM res_baseinfo WHERE hdfs='${hdfs}'")
    List<ResourcesInfoManagerBaseInfo> findBaseInfoByHDFS(@Param("hdfs")Character hdfs);
    @Select("SELECT * FROM res_baseinfo WHERE location='${location}'")
    List<ResourcesInfoManagerBaseInfo>findBaseInfoByLocation(@Param("location")String location);

    @Update("UPDATE res_baseinfo SET " +
            "uid=${baseInfo.uid}," +
            "filename=${baseInfo.filename}," +
            "filesize=${baseinfo.filesize}," +
            "date=${baseinfo.date}," +
            "md5=${baseinfo.md5}," +
            "hdfs=${baseinfo.hdfs}," +
            "location=${baseinfo.location} " +
            "WHERE id=${id}")
    Boolean updateBaseInfoById(@Param("id")Integer id,@Param("baseInfo")ResourcesInfoManagerBaseInfo baseInfo);
    @Update("UPDATE res_baseinfo SET " +
            "uid=${baseInfo.uid}," +
            "filename=${baseInfo.filename}," +
            "filesize=${baseinfo.filesize}," +
            "date=${baseinfo.date}," +
            "md5=${baseinfo.md5}," +
            "hdfs=${baseinfo.hdfs}," +
            "location=${baseinfo.location} " +
            "WHERE uid=${uid}")
    Boolean updateBaseInfoByUid(@Param("uid")String uid,@Param("baseInfo")ResourcesInfoManagerBaseInfo baseInfo);

    @Delete("DELETE FROM res_baseinfo WHERE id=${id}")
    Boolean deleteBaseInfoById(@Param("id")Integer id);
    @Delete("DELETE FROM res_baseinfo WHERE uid=${uid}")
    Boolean deleteBaseInfoByUid(@Param("uid")String uid);

}
